<template>
	<view class="page">
		<view class="center-list">
			<!-- <view class="center-list-item border-bottom" @click="chooseAndUploadFile()">
				<text class="list-text">更改头像</text>
				<image v-model="avatar" class="logo-s" :src="avatar"></image>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
			<view class="center-list-item border-bottom" @click="goto">
				<text class="list-text">修改密码</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view> -->
			<view class="center-list-item border-bottom" @click="edit">
				<text class="list-text">修改个人资料</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
			<view class="center-list-item" @click="bindLogout">
				<text class="list-text">切换账号</text>
				<text class="navigat-arrow">&#xe65e;</text>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		saveUsers
	} from '@/api/user.js'
	export default {
		data() {
			return {
				avatar: uni.getStorageSync('avatar'),
				inviteUrl: '',
				logoutBtnLoading: false
			}
		},
		computed: {},
		onLoad(e) {},
		methods: {
			bindLogout() {
				getApp().exit();
			},
			goto() {
				uni.navigateTo({
					url: '/pages/user/password/password'
				})
			},
			edit() {
				uni.navigateTo({
					url: '/pages/user/personInfo/personInfo',
				})
			},
			chooseAndUploadFile() {
				let that = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: function(res) {
						console.log(JSON.stringify(res.tempFilePaths[0]));
						that.uploadFilePromise(res.tempFilePaths[0]).then(result => {
							saveUsers({
								data: {
									id: uni.getStorageSync('id'),
									avatar: result
								}
							})
							result = result.replace('http://localhost:18000/manage', getApp()
								.globalData.baseUrl)
							that.avatar = result;
							uni.setStorageSync('avatar', that.avatar)
						}).catch(err => {

						})
					}
				});
			},
			uploadFilePromise(url) {
				return new Promise((resolve, reject) => {
					let a = uni.uploadFile({
						url: getApp().globalData.baseUrl + '/system/file/admin/upload', // 仅为示例，非真实的接口地址
						filePath: url,
						name: 'file',
						header: {
							'content-type': 'multipart/form-data',
							'Token': uni.getStorageSync('Token')
						},
						formData: {
							// path: 'feedback'
						},
						success: (res) => {
							setTimeout(() => {
								resolve(JSON.parse(res.data).data)
							}, 1000)
						},
						fail: (err) => {
							console.log(err)
						}
					});
				})
			}
		}
	}
</script>

<style>
	@font-face {
		font-family: texticons;
		font-weight: normal;
		font-style: normal;
		src: url('https://at.alicdn.com/t/font_984210_5cs13ndgqsn.ttf') format('truetype');
	}

	button {
		width: 100%;
	}

	.center {
		flex-direction: column;
	}

	.logo {
		width: 750rpx;
		height: 252rpx;
		padding: 0 32rpx 0 36rpx;
		box-sizing: border-box;
		background-color: #D9D9D9;
		flex-direction: row;
		align-items: center;
		display: flex;
	}

	.logo-hover {
		opacity: 0.8;
	}

	.logo-img {
		width: 120rpx;
		height: 120rpx;
		display: inline-block;
	}

	.logo-title {
		/* height: 150rpx;
		flex: 1;
		align-items: center;
		justify-content: space-between;
		flex-direction: row; */
		margin-left: 32rpx;
		display: inline-block;
		/* position:relative;
		z-index:99999; */
	}

	.uer-name {
		color: #333333;
		font-family: PingFang SC;
		font-weight: bold;
		font-size: 18px;
		line-height: normal;
		letter-spacing: 0px;
		text-align: left;
	}

	.go-login.navigat-arrow {
		color: #FFFFFF;
	}

	.login-title {
		height: 150rpx;
		align-items: self-start;
		justify-content: center;
		flex-direction: column;
		margin-left: 20rpx;
	}

	.center-list {
		background-color: #FFFFFF;
		width: 750rpx;
		flex-direction: column;
		margin-top: 16rpx;
	}

	.center-list-item {
		/* width: 750rpx; */
		box-sizing: border-box;
		flex-direction: row;
		margin: 0 42rpx 0 38rpx;
		padding: 20rpx 0;
		display: flex;
	}

	.border-bottom {
		border-bottom-width: 1rpx;
		border-color: #c8c7cc;
		border-bottom-style: solid;
	}

	.list-icon {
		width: 48rpx;
		height: 48rpx;
		line-height: 90rpx;
		color: #0faeff;
		text-align: center;
		font-family: texticons;
		margin-right: 20rpx;
	}

	.list-text {
		height: 90rpx;
		line-height: 90rpx;
		color: #555;
		flex: 1;
		text-align: left;
	}

	.logo-s {
		height: 48rpx;
		width: 48rpx;
		line-height: 90rpx;
		margin-top: 20rpx;
	}

	.navigat-arrow {
		height: 90rpx;
		width: 40rpx;
		line-height: 90rpx;
		color: #555;
		text-align: right;
		font-family: texticons;
	}

	.re-uni-list-item__content-note {
		color: #999999;
		font-family: PingFang SC;
		font-weight: medium;
		font-size: 13px;
		line-height: normal;
		letter-spacing: 0px;
		text-align: left;
	}

	.rlist-text {
		height: 90rpx;
		line-height: 90rpx;
		flex: 1;
		color: #999999;
		font-family: PingFang SC;
		font-weight: 500;
		font-size: 13px;
		letter-spacing: 0px;
		text-align: right;
	}
</style>